class KthLargest {
    PriorityQueue<Integer> heap=new PriorityQueue<>();
    int kk;
    public KthLargest(int k, int[] nums) {
        kk=k;
        for(int x:nums){
            heap.offer(x);
            if(heap.size()>k){
                heap.poll();
            }
        }
    }
    
    public int add(int val) {
        heap.offer(val);
        if(heap.size()>kk){
            heap.poll();
        }
        return heap.peek();
    }
}